setInterval(checkInfoUpdate,3000);

var currentInfoId = -1;

var labelList = [];
var fieldList = [];
var datetimeField = null;

//按顺序注册接收显示的labelId和textfieldId，前者是<span>，后者是<input type="text">，两者都可以是null,当然，后者null就没意义了
//最后面是更新时间域
function registerTextFields(labelIdList,textfieldIdList,updateTimeFieldId){
	if(labelIdList != null){
		for(var i in labelIdList){
			labelList.push(dojo.byId(labelIdList[i]));
		}
	}
	if(textfieldIdList != null){
		for(var i in textfieldIdList){
			fieldList.push(dojo.byId(textfieldIdList[i]));
		}
	}
	if(updateTimeFieldId != null){
		datetimeField = dojo.byId(updateTimeFieldId);
	}
}

function checkInfoUpdate(){
	dojo.xhrGet({
		 url:"../dashboard/getDashboardInfo.do",
		 handleAs:"json",
		 preventCache:true,
		 content:{boardName:U.getValue("boardName")},
		 load:function(response){
			 var id = response["id"];
			 if(id != 0  && id != currentInfoId){
				 currentInfoId = id;
				 updateCallback(response);
			 }
		 }
	});
}

//真要是想完全自己处理，就由页面重写这个方法
var updateCallback = function(info){
//	var infoStr = "id = "+info["id"]+",更新时间:"+info["updateTime"]+"<br/>";
//	for(var i in info["infoItemList"]){
//		infoStr += (
//				info["infoItemList"][i]["itemName"] + ":" + info["infoItemList"][i]["itemValue"] + "," 
//		);
//	}
//	var n = dojo.create("div", { innerHTML: infoStr+"</br></br>" },dojo.body());
	
	
	
	if(datetimeField != null){
		datetimeField.value = info["updateTime"];
	}
	
	for(var i=0 ; i<info["infoItemList"].length ; i++){
		if(labelList != null){
			labelList[i].innerHTML = info["infoItemList"][i]["itemName"];
		}
		if(fieldList != null){
			fieldList[i].value = info["infoItemList"][i]["itemValue"];
		}
	}	
}




